#include <iostream>
#include <string>
#include <regex>
#include <fmt/format.h>
using namespace std;

class A
{
public:
    static constexpr std::string name = "lk";
};
int main()
{
    {
        //lesson 17
        std::string s1{ "1\t2\t3\t4\t5" };
        std::string result{ std::regex_replace(s1, std::regex{ "\t" }, ",") };
        std::cout << fmt::format("Original string: {}\n", R"(1\t2\t3\t4\t5)")
                  << fmt::format("After replacing tabs with commas: {}\n", result);
    }
    {
        //lesson 18
        std::string s1{ "Programing is fun" };
        std::cout << fmt::format("s1: {}\n\n", s1);
        std::cout << "Search anywhere in s1: \n"
                  << fmt::format("Programing: {}; fun: {}; fn: {}\n\n",              //
                                 std::regex_search(s1, std::regex{ "Programing" }),  //
                                 std::regex_search(s1, std::regex{ "fun" }),         //
                                 std::regex_search(s1, std::regex{ "fn" }));

        //std::string s2{ "SAM WHITE" };
        std::string s2{ "SAM WHITE SAM JSON" };
        std::regex pattern{ "Sam", std::regex_constants::icase };
        std::smatch match;
        std::cout << "Case insensitive search for Sam in s2:\n"
                  << fmt::format("Sam: {}\n", std::regex_search(s2, match, pattern))  //
                  << fmt::format("Matched text:{}\n", match.str());
    }
    {
        std::string contact{ "Wally White,Home: 555-555-1234,Work: 555-555-4321" };
        std::regex phone{ R"(\d{3}-\d{3}-\d{4})" };
        std::smatch match;
        std::cout << fmt::format("Finding phone numbers in:\n{}\n", contact);
        while (std::regex_search(contact, match, phone))
        {
            std::cout << fmt::format(" {}\n", match.str());
            //match.suffix   is substring left
            contact = match.suffix();
        }
    }
    return 0;
}
